<script lang="ts" setup>
import { appWindow } from '@tauri-apps/api/window'
import { convertFileSrc } from '@tauri-apps/api/tauri';
import { appDataDir } from '@tauri-apps/api/path';
import {onMounted, ref} from 'vue'
const src = ref<string>();
onMounted(async ()=>{
    const appData = await appDataDir();
    src.value = appData+appWindow.label+'.png';
    // const uint8Array =await readBinaryFile(src.value);  
    // const arrayBuffer = uint8Array.buffer;
    // const blob = new Blob([arrayBuffer], {type: 'image/png'});

    src.value = convertFileSrc(src.value);

    try {
        const data = await fetch(src.value);
        const blob = await data.blob();
        await navigator.clipboard.write([
            new ClipboardItem({
                [blob.type]: blob
            })
        ]);
        console.log('图片已被复制！');
    } catch (err:any) {
        console.error(err.name, err.message);
    }
})


</script>

<template>
<div class="div">
    <img class="img" id="img" :src="src" alt="">
</div>
</template>

<style scoped>
body{
    margin: 0;
    padding: 0;
    border: 0;
}
.div{
    width: 100vw;
    height: 100vh;
    background: black;
}
.img{
    width: 100vw;
    height: auto;
}
</style>